<template>
	<view class="pics">
		<scroll-view class="left" scroll-y="true">
			<view @click="leftClick(index,item.id)" :class="active===index?'active':''" v-for="(item,index) in picList"
				:key="item.id">{{item.title}}
			</view>
		</scroll-view>

		<scroll-view scroll-y="true" class="right">
			<view class="item" v-for="item in secondData" :key="item.id">
				<image
					@click="previewImg(item.img_url)"
					src="https://res.vmallres.com/pimages/uomcdn/CN/pms/202203/gbom/6941487250882/428_428_A1308212EBC5B717A9110FFF9906CC91mp.png"
					mode=""></image>
				<text>{{item.title}}</text>
			</view>
			<text v-if="this.secondData.length===0">暂无数据</text>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				picList: [],
				active: 0,
				secondData: []
			};
		},
		methods: {
			async getPics() {
				const res = await this.$myRequest({
					url: '/api/getimgcategory'
				})
				this.picList = res.data.message
				this.leftClick(0, this.picList[0].id)
			},
			async leftClick(index, id) {
				this.active = index

				const res = await this.$myRequest({
					url: '/api/getimages/' + id
				})
				this.secondData = res.data.message
			},
			previewImg(current){
				const urls=this.secondData.map(item=>{
					return item.img_url
				})
				uni.previewImage({
					current,
					urls
				})
			}
		},
		onLoad() {
			this.getPics()
		}
	}
</script>

<style lang="scss">
	page {
		height: 100%;
	}

	.pics {
		height: 100%;
		display: flex;

		.left {
			width: 200rpx;
			height: 100%;
			border-right: 1px solid #EEEEEE;

			view {
				height: 60px;
				line-height: 60px;
				color: #333;
				text-align: center;
				font-size: 30rpx;
				border-top: 1px solid #EEEEEE;
			}

			.active {
				background-color: $uni-main-color;
				color: #FFFFFF;
			}
		}

		.right {
			height: 100%;
			width: 530rpx;
			margin: 5px auto;

			.item {
				image {
					width: 100%;
					height: 530rpx;
					border-radius: 5px;
				}

				text {
					font-size: 30rpx;
					line-height: 60rpx;
				}
			}
		}
	}
</style>
